import axios from 'axios'
import request from './request'
import store from '../store'

export default class UploadUtils{

    static uploadPhoto(obj,params = {},onSuccess,onError){
        console.log("图片上传")
        const formData = new FormData()
        formData.append("file",obj.file)
        for (let paramsKey in params) {
            formData.append(paramsKey,params[paramsKey])
        }
        const config = {
            headers: { 'Content-Type': 'multipart/form-data' }
        }
        if (store.getters.token) {
            config.headers['X-Token'] = store.getters.token // 让每个请求携带自定义token 请根据实际情况自行修改
        }
        const url = request.baseURL + 'api/console/filestore/upload'
        axios.post(url,formData,config).then(response => {
            console.log(response)
            if (onSuccess){
                onSuccess(response)
            }
        }).catch(error=>{
            console.log(error)
            if (onError){
                onError(error)
            }
        })
    }
}
